<?php
namespace app\madmin\controller;
use app\madmin\model\MallTypesModel;

/**
 * 商品类型控制器
 * @author  黄明杰 vx:HMJ125855
 * @version 20190201
 */
class MallTypes extends PublicBase{

    # 商品类型列表方法
    public function showList(){
        $MallTypes = new MallTypesModel;

        $Where = $this->getFormWhere();

        $types_state = input('param.types_state');
        if(!empty($types_state)){
            $Where['types_state'] = $types_state;
        }
        $this->assign('types_state', $types_state);

        $Lists = $MallTypes->mList($Where, '*', config('CNF_LISTPAGE'));

        # 模版赋值
        return $this->fetch('MallTypes/showList', [
            'Lists' => $Lists
        ]);
    }

    # 商品类型新增方法
    public function showAdd(){
        $MallTypes = new MallTypesModel;

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $MallTypes->mAdd($Param);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            # 模版赋值
            return $this->fetch('MallTypes/showAdd', [
                'Info'  => Null
            ]);
        }
    }

    # 商品类型更新方法
    public function showEdit(){
        $MallTypes = new MallTypesModel;

        $ID = input('param.id');

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $MallTypes->mEdit(['types_id'=>$ID], $Param);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            $Info = $MallTypes->mInfo(['types_id'=>$ID]);

            if(empty($Info)){
                $this->ShowData(2, lang('XtCwCxCw'));
            }else{
                # 模版赋值
                return $this->fetch('MallTypes/showAdd', [
                    'Info'  => $Info
                ]);
            }
        }
    }

    # 商品类型删除方法
    public function showDel(){
        if(request()->isPost()){
            $MallTypes = new MallTypesModel;

            $ID = input('post.id');

            $Back = $MallTypes->mDel(['types_id'=>$ID]);

            $this->ShowData($Back['code'], $Back['msgs']);
        }
    }

}